![]() |
PATH![]() |
![]() ![]() |
Listing 3-4 shows another sample function, MyEditTextFrameUserItemProc , which, depending upon the presence of the Appearance Manager, branches between two functions, each of which draws a frame for an editable text field. In this example, the editable text frame is defined as a dialog user item. Again, prior to drawing, the MyEditTextFrameUserItemProc function calls the MyIsAppearancePresent function, described in Becoming a Client of the Appearance Manager , to determine whether the Appearance Manager is present.
If the Appearance Manager is not present, MyEditTextFrameUserItemProc calls the function MyClassicEditTextFrameUserItemProc . MyClassicEditTextFrameUserItemProc first obtains the frame's rectangle from the Dialog Manager, then supplies the rectangle and a color to QuickDraw to draw the frame. However, an editable text frame drawn in this manner maintains the same "fixed" look in any appearance and cannot adapt to theme switches.
If the Appearance Manager is present, however, MyEditTextFrameUserItemProc calls MyAppearanceSavvyEditTextFrameUserItemProc . MyAppearanceSavvyEditTextFrameUserItemProc then passes the appropriate Appearance Manager constant for the drawing state ( kThemeStateActive or kThemeStateInactive ) to the function DrawThemeEditTextFrame . DrawThemeEditTextFrame draws the frame appropriately for the activity state and the current theme. And, when a theme switch occurs, the frame automatically takes on a look consistent with the current theme.
Listing 3-4 Drawing a dialog user item that is theme-compliant
static pascal void MyClassicEditTextFrameUserItemProc (
WindowPtr window,
DialogItemIndex itemIndex)
{
short iType;
Handle iHandle;
Rect iRect;
GetDialogItem (window,itemIndex,&iType,&iHandle,&iRect);
InsetRect (&iRect,-1,-1);
// We're pre-Appearance Mgr here, so always draw in black...
PenNormal ( );
// unless the editable text field is disabled (inactive); if so, draw in gray
if (iType & kItemDisableBit) PenPat (&(qd.gray));
FrameRect (&iRect);
}
static pascal void MyAppearanceSavvyEditTextFrameUserItemProc (
WindowPtr window,
DialogItemIndex itemIndex)
{
short iType;
Handle iHandle;
Rect iRect;
GetDialogItem (window,itemIndex,&iType,&iHandle,&iRect);
DrawThemeEditTextFrame (&iRect,
(iType & kItemDisableBit) ?
kThemeStateInactive : kThemeStateActive);
}
static pascal void MyEditTextFrameUserItemProc (
WindowPtr window,
DialogItemIndex itemIndex)
{
OSStatus err = noErr;
Boolean haveAppearance;
if (!(err = MyIsAppearancePresent (&haveAppearance)))
{
if (haveAppearance)
MyAppearanceSavvyEditTextFrameUserItemProc (window, itemIndex);
else
MyClassicEditTextFrameUserItemProc (window, itemIndex);
}
}